package cn.wolfcode.p2p.base.controller;

import cn.wolfcode.p2p.anno.NeedLogin;
import cn.wolfcode.p2p.base.domain.IpLog;
import cn.wolfcode.p2p.base.query.IpLogQueryObject;
import cn.wolfcode.p2p.base.service.IAccountService;
import cn.wolfcode.p2p.base.service.IIpLogService;
import cn.wolfcode.p2p.business.service.IExpAccountService;
import cn.wolfcode.p2p.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
/**
 * 用户个人中心
 */
@Controller
public class PersonalController {
    @Autowired
    private IAccountService accountService;

    @Autowired
    private IIpLogService ipLogServive;

    @Autowired
    private IExpAccountService expAccountService;


    @NeedLogin
    @RequestMapping("personal")
    public String personal(Model model,IpLogQueryObject qo){
        //获取用户的信息
        Long currentUserId = UserContext.getLoginInfo().getId();
        model.addAttribute("account",accountService.getAccount(currentUserId));
        model.addAttribute("expAccount",expAccountService.getExpAccount(currentUserId));
        //获取用户最后一次登陆的时间
        qo.setPageSize(1);
        model.addAttribute("lastLoginHistory",(IpLog)ipLogServive.query(qo).getListData().get(0));
        return "personal";
    }




}
